package leetcode.f1t100;

/**
 * 三色排序
 * https://leetcode.com/problems/sort-colors/
 * @Author lichongxiao
 * @Date 2022/11/24 10:05
 */
public class Q75_SortColor {
    public void sortColors(int[] nums) {
        int[] counts = new int[3];
        for(int num : nums){
            counts[num]++;
        }
        for (int i = 0,j=0, length = nums.length; i < length ; i++) {
            while(counts[j] <= 0){
                j++;
            }
            nums[i] = j;
            counts[j]--;
        }
    }

    public static void main(String[] args) {
        Q75_SortColor bean = new Q75_SortColor();
        int[] a =  new int[]{2,2,2,2};
        bean.sortColors(a);
        for(int i : a){
            System.out.println(i);
        }
    }
}
